﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BiffenGUI.BiffenService;

namespace BiffenGUI.UserControls
{
    public partial class ShowSeats : UserControl
    {

        public BiffenServiceClient ServiceClient { get; set; }
        SeatTableHelper helper;
        
        public ShowSeats()
        {
            InitializeComponent();
        }

        public void Clear()
        {
            seatGrid.Columns.Clear();
            seatGrid.Rows.Clear();
        }

        public void UpdateShow(Show show)
        {
            // Clear table
            Clear();

            // update the table
            int rows = show.Theater.NoRows;
            int cols = show.Theater.NoCols;
            
            helper = new SeatTableHelper(seatGrid, rows, cols);
            List<Booking> bookings = ServiceClient.GetBookingsForShow(show);
            helper.SetBookings(bookings);
            seatGrid.ClearSelection();
        }
        
        public List<int> GetAllSeats()
        {
            return helper.GetSelectedSeats();
        }

        private void seatGrid_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e)
        {
            helper.ToggleSeat(e.RowIndex, e.ColumnIndex);
            seatGrid.ClearSelection();

            if (Parent.GetType() == typeof(MemberAddBookingCreate))
            {
                ((MemberAddBookingCreate)Parent).UpdatePrice();
            }
            else if (Parent.GetType() == typeof(BookingAdd))
            {
                ((BookingAdd)Parent).UpdatePrice();
            }
        }
    }
}
